//
// Created by gogoqiu on 2022/3/24.
//

#include "BaseItem.h"

BaseItem* BaseItem::NullValueItem( const wxString& key,
                                               const wxString& defaultValue){
    auto* item = new BaseItem;
    item->key = key;
    //item->value = 0;
    return item;
}


wxString BaseItem::getInsertSql( const wxString& tag ){
    wxString sql;
    wxString _value = value;
    //把26个字母打一遍，然后通过php的addslashes查看哪些字符变化了
    _value.Replace("\\", "\\\\");
    _value.Replace("\"", "\\\"");
    _value.Replace("\'", "\\\'");
    //sql.sprintf(base, filename, filesize, file_hash);
    sql.sprintf("insert into preferences( appId, key, defaultValue, value, prompt, description ) values( '%s', '%s', '%s', '%s', '%s', '%s' )",
                tag, key, this->defaultValue, _value, prompt, description );
    //wxString _sql = sql.mb_str(wxConvUTF8);
    return sql;
}

wxString BaseItem::getSelectSql(const wxString &tag) {
    wxString sql;
    sql.sprintf("select * from preferences where appId='%s' and key='%s';",
                tag, key );
    return sql;
}

